package com.atguigu.juc.study.chapter13.aqs;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author : leimingchao
 * @date Date : 2022年06月21日 0:37
 */
public class AQSDemo {

    public static void main(String[] args) {

        Lock lock = new ReentrantLock();

        new Thread(() -> {
            lock.lock();

            try {
                System.out.println("----come in A");
                try {
                    TimeUnit.MINUTES.sleep(20);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            } finally {

                lock.unlock();
            }
        }, "A").start();

        new Thread(() -> {
            lock.lock();

            try {
                System.out.println("---- come in B");
            } finally {

                lock.unlock();
            }
        }, "B").start();


        new Thread(() -> {
            lock.lock();

            try {
                System.out.println("----come in C");
            } finally {

                lock.unlock();
            }
        }, "C").start();

        new Thread(() -> {
            lock.lock();

            try {
                System.out.println("---- come in D");
            } finally {

                lock.unlock();
            }
        }, "D").start();
    }
}
